﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using HYRevitCode.FormUtility;

namespace YArchitech.HVAC
{
	public partial class FormDeleteInsulationLayers : System.Windows.Forms.Form
	{
		public FormDeleteInsulationLayers()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			List<KeyValuePair<System.Windows.Forms.Control, bool>> inputControlGroup = new List<KeyValuePair<System.Windows.Forms.Control, bool>>();
			this.m_thisManger = new ControlInfoManager(this, inputControlGroup, "{7E142781-2F17-466F-8C85-202344E49D7F}", null);
			base.Icon = Resource.YArchitechIcon;
			this.BeManualCancel = false;
		}

		private void FormDeleteInsulationLayers_Load(object sender, EventArgs e)
		{
			if (this.m_thisManger != null && !this.m_thisManger.SetControlInfoToForm())
			{
				base.Location = new System.Drawing.Point(230, 170);
			}
			base.KeyPreview = true;
		}

		public bool BeManualCancel { get; set; }

		public bool GetDeleteType()
		{
			return this.rdoSystem.Checked;
		}

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		private void SendSetfocusMessage()
		{
			int wMsg = 7;
			FormDeleteInsulationLayers.SendMessage(DeleteInsulationMaterials.hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
		}

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		private void SimulationPressESC()
		{
			int bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			FormDeleteInsulationLayers.keybd_event((byte)bVk, 0, dwFlags, 0);
			FormDeleteInsulationLayers.keybd_event((byte)bVk, 0, dwFlags2, 0);
		}

		private void FormDeleteInsulationLayers_MouseLeave(object sender, EventArgs e)
		{
			if (!base.ClientRectangle.Contains(base.PointToClient(Cursor.Position)))
			{
				this.SendSetfocusMessage();
				return;
			}
			base.Focus();
		}

		private void FormDeleteInsulationLayers_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SendSetfocusMessage();
			this.SimulationPressESC();
			this.SimulationPressESC();
		}

		private void ChangeOperateState()
		{
			Cursor.Position = new System.Drawing.Point(Cursor.Position.X, base.Bottom + 1);
			this.SendSetfocusMessage();
			this.SimulationPressESC();
		}

		private void rdoSystem_CheckedChanged(object sender, EventArgs e)
		{
			RadioButton radioButton = sender as RadioButton;
			if (radioButton != null && radioButton.Checked)
			{
				this.BeManualCancel = true;
				this.ChangeOperateState();
			}
		}

		private void FormDeleteInsulationLayers_KeyDown(object sender, KeyEventArgs e)
		{
		}

		private void button1_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void FormDeleteInsulationLayers_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\u001b')
			{
				base.Close();
			}
		}

		private void FormDeleteInsulationLayers_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (this.m_thisManger != null)
			{
				this.m_thisManger.GetControlInfoToXml();
			}
		}

		private ControlInfoManager m_thisManger;
	}
}
